<?php
$display = '<table summary="Affichage" id="results">'."\n";
// Nom des champs
$display .= '<tr style="background-color:#F3F3F3; border:1px;">';
	foreach($results[0] as $key=>$value){
		if(!is_numeric($key)){
			$display .= '<td style="color:black;">'.$select[$key].'</td>';
		}
	}
$display .= '<td style="color:black;">Lien NUMDAM</td></tr>'."\n";
// Affichage des résultats
$i=1;
foreach($results as $key=>$value){
	// coloration lignes paires
	if(is_int($i/2))$backgroundColor = '#F3F3F3';
	else $backgroundColor = 'white';
	$display .= '<tr style="background-color:'.$backgroundColor.';">';
	$i++;
	foreach ($value as $key1=>$value1){
		if(!is_numeric($key1)){
			// Valeur d'origine pour le lien
			$valueLink = $value1;
			// Affichage en recherche simple
			if(!empty($_GET['s'])) {
 				// Surlignage du motif
 				$chaine = $_GET['s'];
				$chaine_r = utf8_decode ( $chaine );
				$value2 = utf8_decode ( $value1 );
				$chaine_r = preg_replace ("/\\W/",".",$chaine_r);
				$value1 = preg_replace("/($chaine_r)/i", '<span class="highlight">$1</span>', $value2);
				$value1 = utf8_encode($value1);
			}
			// Affichage en recherche avancée
			if(!empty($_GET['a'])){
				if (!empty($_GET[$key1]))	$value1 = '<span class="highlight">'.$value1.'</span>';
			}
			// Lien interne
			$value1 = '<a href="?a=on&amp;'.$key1.'='.urlencode($valueLink).'&amp;action=go">'.$value1.'</a>';

			// Affichage des champs
			if($key1=='lnfn') $display .= '<td style="padding:0.4em;white-space: nowrap;background-color:#dde9f8;">'.$value1.'</td>';
			else $display .= '<td>'.$value1.'</td>';
		}
	}
	// Calcul du lien NUMDAM
	$urlNumdam = 'http://www.numdam.org/numdam-bin/feuilleter?id=NAM_'.$value['yrvol'];
	// Calcul de la série et du tome
	if ($value['yrvol'] >= '1842' and $value['yrvol'] <= '1861') $urlNumdam .= '_1_'.($value['yrvol']-1842+1).'_';
	if ($value['yrvol'] >= '1862' and $value['yrvol'] <= '1881') $urlNumdam .= '_2_'.($value['yrvol']-1862+1).'_';
	if ($value['yrvol'] >= '1882' and $value['yrvol'] <= '1900') $urlNumdam .= '_3_'.($value['yrvol']-1882+1).'_';
	if ($value['yrvol'] >= '1901' and $value['yrvol'] <= '1920') $urlNumdam .= '_4_'.($value['yrvol']-1901+1).'_';
	if ($value['yrvol'] >= '1922' and $value['yrvol'] <= '1924') $urlNumdam .= '_5_'.($value['yrvol']-1842+1).'_';
	if ($value['yrvol'] == '1925') $urlNumdam .= '_6_1_';
	if ($value['yrvol'] == '1927') $urlNumdam .= '_6_2_';
	$display .= '<td class="center">';
	$display .= '<a href="'.$urlNumdam.'" target="_blank" title="Volume \''.$value['yrvol'].'\' dans NUMDAM"><img src="images/N.jpg" alt="Numdam"/></a> ';
	$display .= '</td>';
	$display .= '</tr>'."\n";
}
$display .= '</table>'."\n";

echo $display;

//print_r($results);

?>